package com.monitor.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.monitor.system.domain.vo.HardDeviceVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.monitor.common.annotation.Log;
import com.monitor.common.core.controller.BaseController;
import com.monitor.common.core.domain.AjaxResult;
import com.monitor.common.enums.BusinessType;
import com.monitor.system.domain.HardDevice;
import com.monitor.system.service.IHardDeviceService;
import com.monitor.common.utils.poi.ExcelUtil;
import com.monitor.common.core.page.TableDataInfo;

/**
 * 硬件设备Controller
 * 
 * @author monitor
 * @date 2024-06-13
 */
@RestController
@RequestMapping("/system/device")
public class HardDeviceController extends BaseController
{
    @Autowired
    private IHardDeviceService hardDeviceService;

    /**
     * 查询硬件设备列表
     */
    @ApiOperation("查询硬件设备列表")
//    @PreAuthorize("@ss.hasPermi('system:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(HardDevice hardDevice)
    {
        startPage();
        List<HardDevice> list = hardDeviceService.selectHardDeviceList(hardDevice);
        return getDataTable(list);
    }

    /**
     * 导出硬件设备列表
     */
    @ApiOperation("导出硬件设备列表")
    @PreAuthorize("@ss.hasPermi('system:device:export')")
    @Log(title = "硬件设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HardDevice hardDevice)
    {
        List<HardDevice> list = hardDeviceService.selectHardDeviceList(hardDevice);
        ExcelUtil<HardDevice> util = new ExcelUtil<HardDevice>(HardDevice.class);
        util.exportExcel(response, list, "硬件设备数据");
    }

    /**
     * 获取硬件设备详细信息
     */
    @ApiOperation("获取硬件设备详细信息")
    @PreAuthorize("@ss.hasPermi('system:device:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hardDeviceService.selectHardDeviceById(id));
    }

    /**
     * 新增硬件设备
     */
    @ApiOperation("新增硬件设备")
    @PreAuthorize("@ss.hasPermi('system:device:add')")
    @Log(title = "硬件设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HardDevice hardDevice)
    {
        return toAjax(hardDeviceService.insertHardDevice(hardDevice));
    }

    /**
     * 修改硬件设备
     */
    @ApiOperation("修改硬件设备")
    @PreAuthorize("@ss.hasPermi('system:device:edit')")
    @Log(title = "硬件设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HardDevice hardDevice)
    {
        return toAjax(hardDeviceService.updateHardDevice(hardDevice));
    }

    /**
     * 删除硬件设备
     */
    @ApiOperation("删除硬件设备")
    @PreAuthorize("@ss.hasPermi('system:device:remove')")
    @Log(title = "硬件设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hardDeviceService.deleteHardDeviceByIds(ids));
    }

    /**
     * 查询硬件设备列表
     */
    @ApiOperation("查询硬件设备列表-仪表盘用")
    @GetMapping("/instrumentPanelList")
    public HardDeviceVo instrumentPanelList(HardDevice hardDevice)
    {
        HardDeviceVo vo = hardDeviceService.selectInstrumentPanelList(hardDevice);
        return vo;
    }
}
